package com.mysoft.gfyx.clue.controller.option;

import com.mysoft.framework.modeling.OptionDataController;
import com.mysoft.framework.modeling.dto.Filter;
import com.mysoft.framework.modeling.dto.OptionItem;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.gfyx.clue.remoteservice.RemoteAreaService;
import com.mysoft.gfyx.clue.remoteservice.dto.AreaDto;
import com.mysoft.gfyx.clue.remoteservice.dto.ProvinceAndCityConditionDto;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Tag(name = "省份备选项-API")
@PubService(value = "/provinceOptionData", prefix = RequestPrefix.API, method = {})
public class ProvinceProfitOptionDataController extends OptionDataController {

    @Autowired
    private RemoteAreaService remoteAreaService;

    @Override
    protected List<OptionItem> load(List<Filter> filters, Map<String, String> urlParams) {
        List<OptionItem> items = new ArrayList<>();
        ProvinceAndCityConditionDto conditionDto = new ProvinceAndCityConditionDto();
        List<AreaDto> res = remoteAreaService.getProvince(conditionDto);

        res.forEach(areaDto -> {

            OptionItem item = new OptionItem();
            item.setValue(areaDto.getItemCode());
            item.setParent(areaDto.getParentCode());
            item.setText(areaDto.getItemName());

            items.add(item);
        });

        return items;
    }
}
